<template>
	<view class="dialog">
		<el-dialog :title="title" :visible.sync="dialogVisible" width="40%" :before-close="handleDialogClose">
			<!-- 财务认证审核 or 提现审核 -->
			<el-form ref="form" label-width="130px" v-if="!second">
				<el-form-item label="公司名称:" class="item" prop="companyName">
					<view>{{ item.companyName }}</view>
				</el-form-item>
				<el-form-item label="公司地址:" class="item" prop="companyAddress">
					<view>{{ item.companyAddress }}</view>
				</el-form-item>
				<el-form-item label="开户行地址:" class="item" prop="bankAddress">
					<view>{{ item.bankAddress }}</view>
				</el-form-item>
				<el-form-item label="开户行名称:" class="item" prop="bankName">
					<view>{{ item.bankName }}</view>
				</el-form-item>
				<el-form-item label="银行卡号:" class="item" prop="bankNumber">
					<view>{{ item.bankNumber }}</view>
				</el-form-item>
				<el-form-item label="营业执照:" class="item" prop="businessLicense">
					<view>
						<image :src="item.businessLicense" mode="widthFix"></image>
					</view>
				</el-form-item>
				<el-form-item label="收款证明:" class="item" prop="gatheringProof">
					<view>
						<image :src="item.gatheringProof" mode="widthFix"></image>
					</view>
				</el-form-item>
			</el-form>
			<el-form ref="form" label-width="130px" v-if="second">
				<el-form-item label="提现单号:" class="item" prop="companyName">
					<view>{{ item.orderNumber }}</view>
				</el-form-item>
				<el-form-item label="联系人:" class="item" prop="companyAddress">
					<view>{{ item.contactPerson }}</view>
				</el-form-item>
				<el-form-item label="联系电话:" class="item" prop="bankAddress">
					<view>{{ item.contactPhone }}</view>
				</el-form-item>
				<el-form-item label="提现时间:" class="item" prop="bankName">
					<view>{{ item.createTime && new Date(item.createTime).format() }}</view>
				</el-form-item>
				<el-form-item label="提现金额:" class="item" prop="bankNumber">
					<view>{{ item.amount }}</view>
				</el-form-item>
				<el-form-item label="审核状态:" class="item" prop="businessLicense">
					<view class="yes">{{ getStatusTitle(item.amountStatus) }}</view>
				</el-form-item>
				<el-form-item label="确认审核:" class="item" prop="gatheringProof">
					<el-select v-model="value" placeholder="请选择" class="w50">
					    <el-option
					      v-for="item in options"
					      :key="item.value"
					      :label="item.label"
					      :value="item.value">
					    </el-option>
					  </el-select>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer" v-if="!second">
				<el-button type="primary" @click="handleClose(1)" v-preventReClick>审核通过</el-button>
				<el-button type="danger" @click="handleClose(2)" v-preventReClick>审核拒绝</el-button>
				<el-button @click="handleClose(false)">取消</el-button>
			</span>
			<span slot="footer" class="dialog-footer" v-if="second">
				<el-button type="primary" @click="handleClose(1)" v-preventReClick>提交</el-button>
				<el-button @click="handleClose(false)">取消</el-button>
			</span>
		</el-dialog>
	</view>
</template>
<script>
	import {
		Request
	} from '../../model/request.js'
	import {
		Util
	} from '../../utils/util.js'
	// import {
	// 	config
	// } from "../../api/config.js";
	// import {
	// 	ServerUrl
	// } from "../../api/server_url.js";
	export default {
		props: {
			dialogVisible: '',
			second: '',
			title: {
				type: String,
				default: '财务审核'
			},
			item: {}
		},
		
		data() {
			return {
				options: [],
				value: ''
			}
		},
		
		watch: {
			item: {
				handler() {
					console.log(this.item, 'eee')
					if (this.item.amountStatus == 1) {
						this.options = [{
							  value: '4',
							  label: '已打款'
							}]
					} else {
						this.options = [{
							  value: '1',
							  label: '审核通过'
							}, {
							  value: '3',
							  label: '审核拒绝'
							}, {
							  value: '4',
							  label: '已打款'
							}]
					}
				},
				immediate: true
			}
		},
		
		methods: {
			getStatusTitle(i) {
				if (i == 1) {
					return '审核通过'
				} else if (i == 2) {
					return '待审核'
				} else if (i == 3) {
					return '审核拒绝'
				} else {
					return '已打款'
				}
			},
			
			handleDialogClose(flag=false) {
				this.value = ''
				this.$emit('closeDialog', flag)
				this.$nextTick(() => {
					this.$refs.form.clearValidate()
				})
			},
			
			async handleClose(e) {
				if (e == 1) { // 通过
					if (this.second) { // 提现
						if (!this.value) {
							return false
						}
						let res = await Request.WITHDRAWALUPDATE(this.item.id, this.value)
						if (res.code == 200) {
							Util.showToast('审核成功')
							this.handleDialogClose(true)
						}
					} else { // 财务认证
						let res = await Request.CERTIFICATIONUPDATE(this.item.id, 0)
						if (res.code == 200) {
							Util.showToast('审核成功')
							this.handleDialogClose(true)
						}
					}
				} else if (e == 2) { // 拒绝
					let res = await Request.CERTIFICATIONUPDATE(this.item.id, 1)
					if (res.code == 200) {
						Util.showToast('审核成功')
						this.handleDialogClose(true)
					}
				} else { // 取消
					this.handleDialogClose()
				}
			}
		}
	}
</script>
<style scoped>
	.dialog {
		/* width: 100%;
	height: 100%; */
		position: absolute;
		left: 0;
		top: 0;
	}

	.el-form-item {
		position: relative;
	}

	/* .el-form-item::before {
		content: '*';
		position: absolute;
		left: 100px;
		top: 13px;
		color: red;
	} */

	/deep/ .item .el-form-item__label {
		position: relative;
		/* left: -20px; */
		/* color: red;
		border: solid 1px red;
		margin-left: 30px; */
	}

	/deep/ .item .el-form-item__label::before {
		content: ' ' !important;
	}

	.photo {
		width: 299px;
		height: 200px;
	}
	
	.el-select {
		width: 100%;
	}
	
	.yes {
		color: #1eee1e;
	}
	
	.w50 {
		width: 50%;
	}
</style>
